package Question14;

import java.util.regex.Pattern;

/**
 * Created by lenovo on 2017/3/13.
 */
public class Question14 {
    /**
     * 随机模拟庄家和玩家的选择
     * @return
     */
    private static Integer[] random(){
        Integer[] results = new Integer[4];

        for(int i = 0;i<4;i++){
            results[i] = (int)(Math.random()*6)+1;
        }
        return results;
    }

    private static Integer cal(Integer[] results){
        int count =0;
        for(int i =0;i<3;i++){
            if(results[i].equals(results[3])){
                count++;
            }
        }

        if(count == 1){
            return -1;
        }else if(count == 2){
            return -2;
        }else if(count == 3){
            return -6;
        }else{
            if (Question14.pingJu(results)) {
                return 0;
            }else{
                return 1;
            }
        }
    }

    /**
     * 判断是否平局
     * @param results
     * @return
     */
    private static Boolean pingJu(Integer[] results){
        if((results[1]*results[2]) == (results[0]*results[3]) || (results[0]*results[2]) == (results[1]*results[3]) || (results[0]*results[1]) == (results[2]*results[3])){
                  return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }




    public static void main(String[] args){
        int sum = 0;
        for(int i=0;i<500000;i++){
            Integer[] results = Question14.random();
            sum+=Question14.cal(results);
        }
        System.out.println("赢率为："+sum*1.0/500000);
    }
}
